package vip.youngboy.freejump.db.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DBTable<C extends DBColumn> implements Serializable {

    protected String name;

    protected String comment;

    protected List<C> columns;

    public DBTable() {
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getComment() {
        return this.comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public List<C> getColumns() {
        return this.columns;
    }

    public void setColumns(List<C> columns) {
        this.columns = columns;
    }

    public C getPkColumn() {
        if (this.columns == null) {
            return null;
        } else {
            List<C> list = new ArrayList();
            Iterator var2 = this.getColumns().iterator();

            while (var2.hasNext()) {
                C c = (C) var2.next();
                if (c.isPrimary()) {
                    list.add(c);
                }
            }

            if (list.isEmpty()) {
                return null;
            } else {
                return list.get(0);
            }
        }
    }

    public C getColumn(String name) {
        if (this.columns == null) {
            return null;
        } else {
            Iterator var2 = this.columns.iterator();

            DBColumn c;
            do {
                if (!var2.hasNext()) {
                    return null;
                }

                c = (DBColumn) var2.next();
            } while (!name.equals(c.getName()));

            return (C) c;
        }
    }
}
